//
//  NewsTableViewCell.swift
//  知乎日报Demo
//
//  Created by Ann on 2017/10/18.
//  Copyright © 2017年 Ann. All rights reserved.
//

import UIKit
import SnapKit
import Kingfisher
let spaceMargin = 10
//Step.4 自定义TableViewCell
class NewsTableViewCell: UITableViewCell {
    
    var news:Status?{
        didSet{
            
            newsImage.kf.setImage(with: URL(string: news?.images?[0] ?? ""))//.image = //UIImage(named: news?.images?[0] ?? "")
            
            newsLabel.text = news?.title ?? ""
        }
    }
    lazy var newsImage: UIImageView = {
        let i = UIImageView()
        i.sizeToFit()
        i.layer.cornerRadius = 4
        i.clipsToBounds = true
        return i
    }()
    lazy var newsLabel:UILabel = {
        let l = UILabel()
        l.font = UIFont.boldSystemFont(ofSize: 16)
        l.textColor = UIColor.darkGray
        l.sizeToFit()
        l.numberOfLines = 0
        return l
    }()
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    override func awakeFromNib() {
        super.awakeFromNib()
        print("awakeFromNib:\(awakeFromNib)")
    }
    
    func setupUI(){
        
        
        self.contentView.addSubview(newsLabel)
        self.contentView.addSubview(newsImage)
        layoutNewsSubView()
        
    }
    override func layoutSubviews() {
        super.layoutSubviews()
        
    }
    
    func layoutNewsSubView(){
        
        
        newsImage.snp.makeConstraints { (make) in
            make.top.equalTo(contentView.snp.top).offset(spaceMargin)
            make.bottom.equalTo(contentView.snp.bottom).offset(-spaceMargin)
            make.right.equalTo(contentView.snp.right).offset(-spaceMargin)
            make.width.equalTo(100)
        }
        newsLabel.snp.makeConstraints { (make) in
            make.left.equalTo(contentView.snp.left).offset(spaceMargin)
            make.top.equalTo(contentView.snp.top).offset(spaceMargin)
            make.right.equalTo(newsImage.snp.left).offset(-spaceMargin)
            make.bottom.equalTo(contentView.snp.bottom).offset(-spaceMargin)
        }
        
    }
    
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
        //selected
        
    }
    
}
